package main

import (
	"bufio"
	"fmt"
	"log"
	"net"
	"os"
)

// go run client.go
func main() {
	conn, err := net.Dial("tcp", "localhost:8080")
	if err != nil {
		log.Println("连接失败:", err)
		return
	}

	defer conn.Close()
	fmt.Println("连接成功")

	go func() {
		scanner := bufio.NewScanner(conn)
		for scanner.Scan() {
			fmt.Println(scanner.Text())
		}
	}()
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		_, err := conn.Write([]byte(scanner.Text() + "\n"))
		if err != nil {
			log.Println("发送失败:", err)
			return
		}
	}
}
